package com.gameley.dmgtpf.common.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 流相关的操作方法封装
 * @qualiFild nc.pub.itf.tools.pub.StreamUtil.java<br>
 * @author：licheng<br>
 * @date Created on 2019-8-12<br>
 * @version 1.0<br>
 */
public final class StreamUtil implements PubConsUtil
{
    /**
     * *********************************************************** <br>
     * 说明： 将InputStream转换成String<br>
     * @see <br>
     * @param in
     * @return
     * @throws IOException <br>
     * @String <br>
     * @methods pers.bc.utils.file.StreamUtilbc#InputStreamTOString <br>
     * @author licheng <br>
     * @date Created on 2020年1月6日 <br>
     * @time 上午11:56:26 <br>
     * @version 1.0 <br>
     *************************************************************          <br>
     */
    public static String InputStreamTOString(InputStream in) throws IOException
    {
        
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] data = new byte[BUFFER_SIZE];
        int count = 0;
        while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
            outStream.write(data, 0, count);
        }
        byte[] byteArray = outStream.toByteArray();
        LoggerUtil.close(in, outStream);
        
        return new String(byteArray, UTF_8);
    }
}
